import functools


class Limit(object):

    def limit_error_case(self, f):
        self.f = f
        return self.f

    def limit_send_email(self, key=None, time=60*2):

        def decorator(f):
            @functools.wraps(f)
            def wrapper(*args, **kwargs):
                from app import cache
                if cache.get(key):
                    return self.f()
                cache.set(key, time, timeout=time)
                return f(*args, **kwargs)

            return wrapper

        return decorator